import java.net.*;
import java.io.*;

public class NaverReader {
	
	public void runUrl(String url,String text)throws Exception{
		URL doUrl = null;
		URLConnection urlCon=null;
		OutputStreamWriter output=null;
		BufferedReader br = null;
		String line=null;
		try {
			doUrl=	new URL(url);
			urlCon= doUrl.openConnection();
			urlCon.setDoOutput(true);
			output= new OutputStreamWriter(urlCon.getOutputStream()); //URLConnection으로부터 출력스트림을 생성하여 출력스트림으로 데이터를 해당 URL로 전송
			output.write(URLEncoder.encode(text));
			output.flush();
			br= new BufferedReader(new InputStreamReader(urlCon.getInputStream()));
		
		while((line=br.readLine()) != null){
			System.out.println(line);
		}
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			output.close();
			br.close();
		}		
	}

	public static void main(String[] args) throws Exception {
		NaverReader na = new NaverReader();
		na.runUrl("http://www.naver.com", "모토로이");

	}

}
